#include "SoundThread.h"

SoundThread::SoundThread(SoundInterface &sdInter):m_sdInter(sdInter)
{
	stop = false;
}

SoundThread::~SoundThread()
{
	Stop();
}

int SoundThread::Start()
{
	if (JThread::IsRunning())
	{
		return -1;
	}
	if (!stop_mutex.IsInitialized())
	{
		if (stop_mutex.Init()<0)
		{
			return -2;
		}
	}
	stop = false;
	if (JThread::Start()<0)
	{
		return -3;
	}
	return 0;
}

void SoundThread::Stop()
{
	if (!IsRunning())
	{
		return ;
	}
	stop_mutex.Lock();
	stop = true;
	stop_mutex.Unlock();
	bool done = false;
	if (JThread::IsRunning())
	{
		JThread::Kill();
	}
	stop = false;	
}

void* SoundThread::Thread()
{
	JThread::ThreadStarted();
	while(stop==false)
	{
		m_sdInter.win_thread();
		printf("SoundThread::Thread\n");
	}
	return NULL;	
}